<?php
/**
 * Created by Dumitru Russu
 * User: developer
 * Date: 10/15/12
 * Time: 5:05 PM
 * To change this template use File | Settings | File Templates.
 */
class Db_Products_ProductsPoems extends Common {
	protected static $tableName = TAB_PRODUCTS_POEMS;
	protected static $dbFields = array(
		'id',
		'pps_product_id',
		'pps_poem_id'
	);

	/**
	 * @var Db_Products_ProductsPoems
	 */
	public $objectArray;

	public $id;
	public $pps_product_id;
	public $pps_poem_id;

	function __construct($value=NULL, $fieldName=NULL) {
		parent::__construct($value, $fieldName);
	}

	/**
	 * deleteProductsPoems, removed from products poems which is unchecked
	 *
	 * @static
	 * @param $productId
	 * @param $poemId
	 * @return bool
	 */
	public static function deleteProductsPoems($productId, $poemId) {
		self::$DB->q('DELETE FROM ?f WHERE `pps_product_id` = ? AND `pps_poem_id` = ? ', self::$tableName, $productId, $poemId);
		return (self::$DB->mysqlModifiedRows() > 0 ? true : false);
	}

	/**
	 * getCheckedProductsPoems return all products poems which were checked
	 *
	 * @static
	 * @return array
	 */
	public static function getCheckedProductsPoems() {
		$sql = 'SELECT * FROM ?f';
		$resultProductsPoems = self::$DB->q($sql, self::$tableName);
		$productsPoems = array();
		while($data = $resultProductsPoems->fetch_object()) {
			$productsPoems[$data->pps_product_id][$data->pps_poem_id] = true;
		}
		return $productsPoems;
	}

}
